package com.hxkcloud.nurse.adapter;

import android.content.Context;
import android.graphics.Color;
import android.util.DisplayMetrics;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.LinearLayout;
import android.widget.TextView;

import com.hxkcloud.nurse.R;
import com.hxkcloud.nurse.beans.MonitorAdapterBean;
import com.hxkcloud.nurse.utils.DpToPxUtils;
import com.hxkcloud.nurse.views.SuperGridView;

import java.util.List;

/**
 * Created by Administrator on 2017/3/23.
 */

public class MonitorPatientAdapter extends SuperGridView.Adapter {
    private Context mContext;
    private LayoutInflater inflater;
    private List<MonitorAdapterBean> list;
    /**
     * 设备屏幕宽度（单位像素）
     */
    private int weight = 0;
    public MonitorPatientAdapter(Context mContext, List<MonitorAdapterBean> list) {
        this.mContext = mContext;
        this.list = list;
        inflater = LayoutInflater.from(mContext);
        DisplayMetrics dm = mContext.getResources().getDisplayMetrics();
        int mWidth = dm.widthPixels;
        weight = (int) ((mWidth - DpToPxUtils.dip2px(mContext, 1)) / 2.0);
    }



    @Override
    public View getView(int position) {
        View view=inflater.inflate(R.layout.item_monitor_patient,null);
        LinearLayout item_reset= (LinearLayout) view.findViewById(R.id.item_reset);
        item_reset.setLayoutParams(new LinearLayout.LayoutParams(weight,(int)(weight*320.0/375.0)));
        TextView txt_title_content = (TextView) view.findViewById(R.id.txt_title_content);
        TextView txt_title_dsc= (TextView) view.findViewById(R.id.txt_title_dsc);
        View txt_title_color =view.findViewById(R.id.txt_title_color);
        txt_title_content.setText(getItem(position).getTitleContent());
        txt_title_dsc.setText(getItem(position).getTitleDes());
        txt_title_color.setBackgroundColor(Color.parseColor(getItem(position).getItemColor()));
        // txt_title_color.setBackgroundResource(Color.parseColor(getItem(position).getItemColor()));
        return view;
    }

    @Override
    public int getCount() {
        return list.size();
    }

    @Override
    public MonitorAdapterBean getItem(int position) {
        return list.get(position);
    }

    @Override
    public long getItemId(int position) {
        return position;
    }
}
